// pages/doctorPages/my/appointModal/appointModal.js
var app = getApp();
const ajax = require("../../../.././utils/ajax.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ruleLength: 0,
    rules: []
  },
  //事件函数
  switchChange: function (e) {
    console.log(e.detail.value)
  },
  addModal: function () {
    wx.navigateTo({
      url: '../addModal/addModal',
    })
  },
  getData:function(){
    wx.showLoading({
      title: '拼命加载中..',
    })
    ajax.request({ url: app.url.doctorGetRules }).then(res => {
      console.log(res)
      let that = this;
      if (res.code == 200) {
        console.log(res.data.length)
        this.setData({
          rules: res.data,
          ruleLength: res.data.length
        });
        let tmpCartData = this.data.rules.map(function (ele, index, array) {
          ele.weekstr = that.setWeeks(ele.weeks)
          return ele;
        });
        this.setData({
          rules: tmpCartData
        });
        wx.hideLoading()
      } else {
        wx.hideLoading()
        wx.showToast({
          title: res.msg,
        })
        
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },
  setWeeks(weeks) {
    let wstr = "";
    for (var i in weeks) {
      if(wstr){
        wstr += "," + app.weeks[weeks[i]]
      }else{
        wstr += app.weeks[weeks[i]]
      }      
    }
    return wstr;
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})